package mybatis;

public class Test {
	public static void main(String[] args) {
	
		// initialize util
        SqlUtil util = new Mylinker();

        // test query1
        User user = new User();
        user.setId(175);
        System.out.println(util.query(user.getClass()));
        // print: SELECT * FROM user WHERE id = 175

        // test query2
        user = new User();
        user.setUsername("史荣贞");
        System.out.println(util.query(user.getClass()));
        // print: SELECT * FROM `user` WHERE `username` LIKE '史荣贞';

        // test insert
        user = new User();
        user.setUsername("user");
        user.setTelephone("12345678123");
        user.setEmail("user@123.com");
        user.setAge(20);
        System.out.println(util.insert(user.getClass(),user));
        // print: INSERT INTO `user` (`username`, `telephone`, `email`, `age`) VALUES ('user', '12345678123', 'user@123.com', 20)
        
        User user2 = new User();
        user2.setId(2);
        user2.setUsername("user2");
        user2.setTelephone("12345678121");
        user2.setEmail("user2@123.com");
        user2.setAge(20);
       
        // test update
        user2.setId(1);
        user2.setUsername("change");
        //user.setTelephone("13600002222");
        user2.setEmail("change@123.com");
       // user.setAge(20);
        System.out.println(util.update(user2.getClass(),user2));
        // print: UPDATE `user` SET `email` = 'change@123.com' WHERE `id` = 1;
        
        // test delete
        user = new User();
        user.setId(1);
        System.out.println(util.delete(user.getClass(),user));

    }

}
